package FTPListing::DOS;

# $Id: DOS.pm 132 2010-06-26 14:46:11Z dolbanavt $
# $Date: 2010-06-26 17:46:16 +0300 (Суб, 26 Июн 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/lib/FTPListing/DOS.pm $
# $LastChangedRevision: 345 $

use parent qw( FTPListing );
use JIP::ToolSet;
use English qw( -no_match_vars );
use Const::Fast qw( const );

our $VERSION = '1.0';

const my $REGEX => qr{
    ^\d\d-\d\d-\d\d\s+\d\d:\d\d\wM # Date and time info
    \s+                            # Some space
    (<\w{3}>|\d+)                  # Dir or Size
    \s+                            # Some more space
    (.+)$                          # File name
}xms;


sub parse_listing_for {
    shift; # shift @ARG;

    my @listing;

    foreach ( @ARG ) {
        my %desc; # file description

        if ( ( $desc{'size_or_dir'}, $desc{'name'} ) = $ARG =~ $REGEX ) {
            if ( $desc{'size_or_dir'} ne '<DIR>' ) {
                $desc{'type'} = 'f';
                $desc{'size'} = $desc{'size_or_dir'};
            }
            else {
                next if $desc{'name'} eq '.' or $desc{'name'} eq '..';

                $desc{'type'} = 'd';
                $desc{'size'} = undef;
            }

            delete $desc{'size_or_dir'};

            push @listing, \%desc;
        }
    }

    return @listing;
}

1;

__END__

=head1 NAME

FTPListing::DOS - класс для парсинга листингов Net::FTP::dir()
в формате DOS.

=head1 SYNOPSIS

    use FTPListing::DOS;

    my @l = FTPListing::DOS->new()->parse_listing_for();

=head1 DEPENDENCIES

Const::Fast (from CPAN)


JIP::ToolSet (from base_lib)

=head1 AUTHOR

Vladimir Zhavoronkov, <dolbanavt (at) Google Mail>

http://dolbanavt.livejournal.com/

=head1 LICENSE AND COPYRIGHT

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

=cut
